<?php 
session_start();
require_once('../include/connect.inc.php');
$q_type_one=1;
$mod_type=3;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
	for ($i=0;$i<$q_type_one;$q_type_one--){
		$type_to_random=$q_type_one % $mod_type;
			if($type_to_random==0){
				echo $type_to_random=$type_to_random+3;
			}else{
			echo $type_to_random;
			}
		}
?>
<?php 
$mod_type=3;
if($nums!=0){
	for ($i=0;$i<$nums;$nums--){
		$lv_to_makeset=$nums % $mod_type;
			if($lv_to_makeset==0){
				$lv_to_makeset=$lv_to_makeset+3;
					$query3 = query("SELECT * FROM tb_question where topic_id=$topic and type_id=$type_id and level_q_id=$lv_to_makeset order by RAND() LIMIT 0,1");
						if(num_rows($query3)<1){
							echo "T3ใส่เงื่อนไข SQL ใหม่";
						}
			}else{
				 $lv_to_makeset;
					$query12 = query("SELECT * FROM tb_question where topic_id=$topic and type_id=$type_id and level_q_id=$lv_to_makeset order by RAND() LIMIT 0,1");
						if(num_rows($query12)<1){
							$query1 = query("SELECT * FROM tb_question where question_id!=$new_q_id and topic_id=$topic and type_id=$type_id and level_q_id='1' order by RAND() LIMIT 0,1");
								while ($rs = fetch_array($query1)) {
									echo $question_id=$rs['question_id'];
									$type_id=$rs['type_id'];
									$new_q_id=$question_id;
								}
						}else{
							while ($rs = fetch_array($query12)) {
								echo $question_id=$rs['question_id'];
								echo "</br>";
								$type_id=$rs['type_id'];
								$new_q_id=$question_id;
							}
						}
			}
		}
}
?>
</body>
</html>
